﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RouterControl.Db;
using RouterControl.Web;

public static class UsageInfoExtensionMethods
{
    public static UsageInfoDb ToDatabase(this UsageInfo info)
    {
        var ui = new UsageInfoDb()
        {
            InstanceId = info.InstanceId,
            VersionId = info.VersionId,
            UploadDateUtc = DateTime.UtcNow,
            ExitPage = info.ExitPage,

            FoundRoutersCount = info.FoundRoutersCount,

            HomeServerVersion = info.HomeServerVersion,
            UpnpStackVersion = info.UpnpStackVersion,
        };

        foreach (var rinfo in info.Routers)
        {
            ui.UsageRouterInfoDbs.Add(new UsageRouterInfoDb()
            {
                ErrorCode = rinfo.ErrorCode,
                ErrorMessage = rinfo.ErrorMessage,
                ExitPage = rinfo.ExitPage,

                Manufacturer = rinfo.Manufacturer,
                ManufacturerUrl = rinfo.ManufacturerUrl,
                RouterDescription = rinfo.RouterDescription,
                RouterModel = rinfo.RouterModel,
                RouterModelNumber = rinfo.RouterModelNumber,
                RouterName = rinfo.RouterName,
                RouterSchemaId = rinfo.RouterSchemaId,

                SupportedManaged = rinfo.SupportedManaged,
                SupportedNative = rinfo.SupportedNative,

                SupportsConnectionSpeed = rinfo.SupportsConnectionSpeed,
                SupportsConnectionStatus = rinfo.SupportsConnectionStatus,
                SupportsHijackingDetection = rinfo.SupportsHijackingDetection,
                SupportsPortForwarding = rinfo.SupportsPortForwarding,
                SupportsTraffic = rinfo.SupportsTraffic,
                SupportsUptime = rinfo.SupportsUptime,
            });
        }

        return ui;
    }

}
